﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TVShow.Framework
{
  public abstract class PluginBase : IPlugin, ILockRequester
  {
    protected string _name;
    public string Name {
      get {
        return _name;
      }
      protected set {
        _name = value;
      }
    }

		protected DisplayManager Display;
		protected INIFile INIfile;
    /// <summary>
    /// Start the plugin and load its settings from the ini file.
    /// </summary>
		public virtual void LoadPlugin(DisplayManager Display) {
			this.Display = Display;
      TVSMessage.RegisterPlugin(this);
			INIfile = GetINIFile(this);
    }

		public static INIFile GetINIFile(IPlugin plugin) {
			string iniPath = PluginManager.INIPath(plugin.GetType().Name);
			return new INIFile(iniPath);
		}

    #region IPlugin Members
		public abstract void ProcessMessage(TVSMessage Event);

    public virtual void ShutDown() {
			TVSMessage.RemovePlugin(this);
    }

		public virtual bool UnlockRequest(DisplayItem Resource) {
			Resource.Clear(this);
			return true;
		}

		#endregion
	}
}
